from flask import Flask
from common.database import init_app
from route.plants import plants_blueprint
from route.User import user_blueprint  # 对应route的蓝图名
from route.Img import img_blueprint
from route.suggest import suggest_blueprint
from route.type import type_blueprint
from route.comment import comment_blueprint
from flask_cors import *

app = Flask(__name__)
CORS(app, resources=r'/*')  # 设置所有跨域
app.config.from_pyfile('config.py')  # 从配置文件加载配置

init_app(app)  # 初始化数据库

# 注册蓝图
app.register_blueprint(plants_blueprint, url_prefix='/plants')  # 文章接口注册
app.register_blueprint(user_blueprint, url_prefix='/user')  # 用户接口注册
app.register_blueprint(img_blueprint, url_prefix='/img')  # 图片接口注册
app.register_blueprint(suggest_blueprint, url_prefix='/suggest')  # 建议接口注册
app.register_blueprint(type_blueprint, url_prefix='/type')  # 建议接口注册
app.register_blueprint(comment_blueprint, url_prefix='/comment')  # 建议接口注册

# 启动文件
if __name__ == '__main__':
    app.run(debug=True)
